package book;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class LibararyTest {

	//1.创建一个Libarary对象
	Libarary lib = new Libarary(5);
	
	// 每个@Test测试之前调用的方法
	@BeforeEach
	void testInsert() {
		Book book1 = new Book(1,"红楼梦","曹雪芹");
		Book book2 = new Book(2,"三国演义","罗贯中");
		Book book3 = new Book(3,"西游记","吴承恩");
		Book book4 = new Book(4,"水浒","施耐庵");
		Book book5 = new Book(5,"三体","刘慈欣");
		Book book6 = new Book(6,"小时代","郭敬明");
		System.out.println(lib.insert(book1));
		System.out.println(lib.insert(book2));
		System.out.println(lib.insert(book3));
		System.out.println(lib.insert(book4));
		System.out.println(lib.insert(book5));
		System.out.println(lib.insert(book6));
	}

	@Test
	void testUpdate() {
		Book book3 = new Book(3,"老人与海","海明威");
		System.out.println(lib.update(book3));
	}

	@Test
	void testDelete() {
		System.out.println(lib.delete(3));
	}

	@Test
	void testSelectById() {
		Book b = lib.selectById(1);
		System.out.println(b.toString());
	}

	// 每个@Test测试之后调用的方法
	@AfterEach
	void testSelectAll() {
		System.out.println("----------------------");
		Book[] books = lib.selectAll();
		for(Book book : books) {
			System.out.println(book.toString());
		}
		System.out.println("----------------------");
	}

	@Test
	void testSelectByName() {
		Book b = lib.selectByName("三体2");
		System.out.println(b);
	}

}
